{%- extends "!layout.html" -%}

{# ========================== 页面元信息设置 ========================== #}
{%- block htmltitle -%}
{# 固定页面标题 #}
<title>{{ project }}</title>
{%- endblock -%}

{%- block scripts -%}
<script>
    /**
     * 控制台过滤器
     */
    class ConsoleFilter {
        // 使用 # 前缀定义私有类字段
        static #originalConsole = {...console};
        static #filters = {
            log: [
                /^\[togglebutton]: Adding toggle buttons to \d+ items$/,
                /^\[PST]: Scrolled sidebar using stored browser position...$/,
                /^\[PST]: Changed to .* mode using the .* theme.$/,
            ],
            info: [],
            debug: [],
            warn: [
                /strict mode: use allowUnionTypes/,
            ]
        };

        static install() {
            ['log', 'info', 'debug', 'warn'].forEach(method => {
                console[method] = (...args) => {
                    if (!this.#shouldFilter(method, args)) {
                        this.#originalConsole[method].apply(console, args);
                    }
                };
            });
        }

        static #shouldFilter(method, args) {
            return (this.#filters[method] || []).some(pattern =>
                args.some(arg => {
                    if (typeof arg !== 'string') return false;
                    const fullMatch = (arg.match(/^([^\n]+)/)?.[0] || arg).trim();
                    return pattern.test(fullMatch);
                })
            );
        }

        static uninstall() {
            Object.keys(this.#originalConsole).forEach(method => {
                console[method] = this.#originalConsole[method];
            });
        }

        static addFilter(method, pattern) {
            if (!this.#filters[method]) {
                this.#filters[method] = [];
            }
            this.#filters[method].push(new RegExp(pattern));
        }
    }
    ConsoleFilter.install();
</script>
{{ super() }}
<!--    <script type="module" src="{{ pathto('_static/libs/youtobe-player/js/player.zh-CN.module.js', 1) }}"></script>-->
<!--    <script type="module" src="{{ pathto('_static/extensions/js/extensions-bundle.min.js', 1) }}"></script>-->
<script type="module"
        src="{{ pathto('_static/assets/js/extensions/device/device-plugin.js', 1) }}"></script>
<script type="module"
        src="{{ pathto('_static/assets/js/extensions/icon/icon-plugin.js', 1) }}"></script>
<script type="module"
        src="{{ pathto('_static/assets/js/extensions/terminal/terminal-plugin.js', 1) }}"></script>
{%- endblock -%}

{# ========================== 彩蛋打印 ========================== #}
{%- block extrahead %}
{# 先保留原主题的JS资源 #}
{{ super() }}
{% include "common/console.html" %}
{%- endblock %}

{# ==========================  页面内容 ========================== #}
{%- block content -%}
{{ super() }}
{%- endblock -%}

{%- block docs_body -%}
{%- include "common/article-meta.html" -%}
{{ super() }}
{%- endblock -%}